home *** CD-ROM | disk | FTP | other *** search
- Public Class Form1
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents txtExpression As System.Windows.Forms.TextBox
- Friend WithEvents btnEval As System.Windows.Forms.Button
- Friend WithEvents txtResult As System.Windows.Forms.TextBox
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.btnEval = New System.Windows.Forms.Button()
- Me.txtExpression = New System.Windows.Forms.TextBox()
- Me.txtResult = New System.Windows.Forms.TextBox()
- Me.SuspendLayout()
- '
- 'Label1
- '
- Me.Label1.Location = New System.Drawing.Point(8, 8)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(248, 24)
- Me.Label1.TabIndex = 0
- Me.Label1.Text = "Enter an expression"
- '
- 'btnEval
- '
- Me.btnEval.Location = New System.Drawing.Point(472, 32)
- Me.btnEval.Name = "btnEval"
- Me.btnEval.Size = New System.Drawing.Size(56, 24)
- Me.btnEval.TabIndex = 3
- Me.btnEval.Text = "&Eval"
- '
- 'txtExpression
- '
- Me.txtExpression.Location = New System.Drawing.Point(8, 32)
- Me.txtExpression.Multiline = True
- Me.txtExpression.Name = "txtExpression"
- Me.txtExpression.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
- Me.txtExpression.Size = New System.Drawing.Size(456, 64)
- Me.txtExpression.TabIndex = 1
- Me.txtExpression.Text = ""
- '
- 'txtResult
- '
- Me.txtResult.BackColor = System.Drawing.Color.WhiteSmoke
- Me.txtResult.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.txtResult.ForeColor = System.Drawing.Color.SteelBlue
- Me.txtResult.Location = New System.Drawing.Point(8, 120)
- Me.txtResult.Name = "txtResult"
- Me.txtResult.Size = New System.Drawing.Size(456, 26)
- Me.txtResult.TabIndex = 2
- Me.txtResult.Text = ""
- '
- 'Form1
- '
- Me.AcceptButton = Me.btnEval
- Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19)
- Me.ClientSize = New System.Drawing.Size(536, 173)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnEval, Me.txtResult, Me.txtExpression, Me.Label1})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Name = "Form1"
- Me.Text = "Expression Evaluator"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- Private Sub btnEval_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEval.Click
- ' evaluate the selected or entire portion of txtSource
- Dim expr As String = txtExpression().SelectedText
- If expr = "" Then expr = txtExpression().Text
- If expr = "" Then Exit Sub
-
- Try
- txtResult.Text = Evaluate(expr).ToString
- Catch ex As Exception
- txtResult.Text = ex.Message
- End Try
- End Sub
- End Class
-